/**
 * 
 */
package top.lcpsky.flashcards.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.lcpsky.flashcards.entity.Todo;
import top.lcpsky.flashcards.service.TodoService;

/**   
 * @ClassName:  ToDoListController   
 * @author: lcp
 * @date:   2020年6月17日 下午2:17:35   
 *     
 * @Copyright: 2020 www.ankept.com Inc. All rights reserved. 
 */
@Controller
@RequestMapping("todo")
public class ToDoListController {

    @Autowired
    private TodoService todoService;

    @PostMapping(value = "add")
    @ResponseBody
	public boolean addTodo(Todo todo) {
        if(todo!=null){
            todo.setContent(todo.getContentStr().getBytes());
            todo.setStatus((byte)0);
            todoService.insert(todo);
            return true;
        }
		return false;
	}

    @GetMapping(value = "delete/{id}")
    @ResponseBody
    public boolean deleteTodoById(@PathVariable("id")Integer id) {
    	Integer[] ids = new Integer[] {id};
		return todoService.deleteByIds(ids);
    }
    
    @GetMapping(value = "update/{id}")
    @ResponseBody
    public boolean deleteTodoStatus(@PathVariable("id")Integer id) {
    	return todoService.updateStatus(id);
    }
}
